using System;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;

namespace SoinusLibrary.Data
{
    public class DBManager
    {
        const int CONNECTED = 1;
        const int DISCONNECTED = 0;

        protected SqlConnection con;
        private int state;

        public DBManager(String connectionString)
        {
            this.state = DBManager.DISCONNECTED;
            this.con = new SqlConnection(connectionString);
        }

        public void Dispose()
        {
            this.con.Close();
            this.con.Dispose();
        }

        protected void Connect()
        {
            if (this.state == DBManager.DISCONNECTED)
            {
                this.con.Open();
                this.state = DBManager.CONNECTED;
            }
        }
        protected void Disconnect()
        {
            if (this.state == DBManager.CONNECTED)
            {
                this.con.Close();
                this.state = DBManager.DISCONNECTED;
            }
        }
    }
}
